//
//  AuthVinChooseCarVC.m
//  New_Runway
//
//  Created by mack on 2018/4/11.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "AuthVinChooseCarVC.h"
#import "CarInfoFormVinModel.h"

@interface AuthVinChooseCarVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, strong) UITableView *tableview;
@property (nonatomic, strong) NSIndexPath *SeleIndexPath;

@end

@implementation AuthVinChooseCarVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBarView.leftItem.hidden = YES;
    self.navigationBarView.titleLabel.text = @"车型匹配";
    self.view.backgroundColor = kColorWhite();
    [self initTableview];
}
-(void)initTableview{
    kSelfWeak;
    self.tableview = [[UITableView alloc] init];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    _tableview.estimatedRowHeight = 0;
    _tableview.estimatedSectionHeaderHeight = 0;
    _tableview.estimatedSectionFooterHeight = 0;
    if (@available(iOS 11.0, *)) {
        self.tableview.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = false;
    }
    self.tableview.backgroundColor = MAIN_COLOR();
    //    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CELL"];
    [self.view addSubview:self.tableview];
    
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view).mas_offset(self.navH);
        make.bottom.equalTo(weakSelf.view).mas_equalTo(-self.BotH);
        make.left.right.equalTo(weakSelf.view);
    }];
    self.tableview.tableFooterView = [[UIView alloc] init];
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.vinCarlist.count ;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL"];
    cell.tintColor = MAIN_NAV_COLOR();
    
    cell.textLabel.textColor = MAIN_FONT_COLOR();
    [cell.textLabel setFont:kFontSize(14)];
    carVinResult *result = self.vinCarlist[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@%@%@",result.series.brandName,result.series.seriesName,result.modelName];
    cell.textLabel.numberOfLines = 2;
    if (self.SeleIndexPath == indexPath) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
        cell.textLabel.textColor = MAIN_NAV_COLOR();
        
    }else{
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    UITableViewCell *celled = [tableView cellForRowAtIndexPath:self.SeleIndexPath];
    celled.accessoryType = UITableViewCellAccessoryNone;
    celled.textLabel.textColor = MAIN_FONT_COLOR();
    //记录当前选中的位置索引
    self.SeleIndexPath = indexPath;
    //当前选择的打勾
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    cell.textLabel.textColor = MAIN_NAV_COLOR();
    [self.tableview reloadData];
    self.block(indexPath.row);
    [self dismissViewControllerAnimated:YES completion:nil];

}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = kColorWhite();
    UILabel *label = [[UILabel alloc] init];
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view).mas_offset(16);
        make.centerY.equalTo(view);
    }];
    label.textColor = UIColorHex(0xff1106);
    label.font = [UIFont systemFontOfSize:13];
    label.text = @"抱歉未匹配到精确车型，请手动选择!";
    UIView *line = [[UIView alloc] init];
    [view addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view);
        make.bottom.equalTo(view).mas_offset(-0.5);
        make.height.mas_equalTo(0.5);
    }];
    line.backgroundColor = UIColorHex(0xe1e1e1);
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 40;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
